package com.zhijiang.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @BelongsProject: hesuan_test_zhijianghospital
 * @BelongsPackage: com.zhijiang.common.config
 * @Author: JunFu
 * @CreateTime: 2022-09-06  16:59
 * @Description: TODO
 * @Version: 1.0
 */
@Configuration
public class GlobalCorsConfig {

    @Bean
    public WebMvcConfigurer corsConfigurer(){
        return  new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedOrigins("*")  // 可跨域的域名，可以为 *
                        .allowCredentials(true)
                        .allowedMethods("GET","POST")   // 允许跨域的方法，可以单独配置
                        .allowedHeaders("*");  // 允许跨域的请求头，可以单独配置

            }
        };
    }

}
